#!/usr/bin/perl -w

# h2chin
# File ID: c9650f12-5d3a-11df-aa5c-90e6ba3022ac
# Konverterer fra numeriske entities til oversatt kinesisk.

use strict;

my %Uh;

$| = 1;

open(FromFP, "</tmp/Unihan-def.txt") || die("Klarte ikke å åpne unihan for lesing: $!");
while(<FromFP>) {
	if (/^U\+(....)\s+kDefinition\s+(.*)/) {
		$Uh{$1} = $2;
		# print (STDERR "$1\n");
	} else {
		# print(STDERR "Bomma på $_\n");
	}
}

close(FromFP);

while (<>) {
	s!&#x([0-9A-F][0-9A-F][0-9A-F][0-9A-F]);!sprintf("\n[%s]", length($Uh{$1}) ? $Uh{$1} : join("", "U+", $1))!gei;	
	print;
}
